package leetcode.editor.cn;

public class P345ReverseVowelsOfAString {
    public static void main(String[] args) {
        Solution solution = new P345ReverseVowelsOfAString().new Solution();
        System.out.println(solution.reverseVowels("aA"));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String reverseVowels(String s) {
            String vowels = "aeiouAEIOU";
            char[] chars = s.toCharArray();
            for (int i = 0, j = chars.length - 1; i < j; ) {
                String l = String.valueOf(chars[i]);
                String r = String.valueOf(chars[j]);
                if (vowels.contains(l) && vowels.contains(r)) {
                    char temp = chars[i];
                    chars[i] = chars[j];
                    chars[j] = temp;
                    i++;
                    j--;
                }
                if (!vowels.contains(l)) {
                    i++;
                }
                if (!vowels.contains(r)) {
                    j--;
                }
            }
            return new String(chars);
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}